<template>
    <div>
    <Form
            ref="form"
            :form-items="formItems"
            :init-data-url="$baseURL.house + '/house/estate/' + $route.params.id"
            :handle-init-data="(data)=>{
                    data.developerCompanyId__label = data.developerCompanyName
                    data.propertyCompanyId__label = data.propertyCompanyName
                    return data
            }"
    ></Form>
    <BaiduMapLocationDialog ref="baiduMapLocationDialog" v-on:selectLocation="(location)=>{
    $refs.form.setFormItem('longitude',location.longitude)
    $refs.form.setFormItem('latitude',location.latitude)
    }">
    </BaiduMapLocationDialog>
    </div>
</template>

<script>
    import Form from '../../../../common-util/src/components/page/Form.vue'
    import BaiduMapLocationDialog from '../../../../common-util/src/components/common/BaiduMapLocationDialog.vue'

    export default {
        components:{
            Form,
            BaiduMapLocationDialog
        },
        data(){
            return {
                formItems:[
                    {
                        field: {
                            name: 'code'
                        },
                        element:{
                            label: '编号',
                            disabled: true
                        }
                    },
                    {
                        field: {
                            name: 'name'
                        },
                        element:{
                            label: '名称',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'nameAlias'
                        },
                        element:{
                            label: '名称别名',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'longitude'
                        },
                        element:{
                            label: '经度',
                            type: 'inputButton',
                            inputButton:{
                                bClick:this.longitudeBtnClick
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'latitude'
                        },
                        element:{
                            label: '纬度',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'provinceAreaId'
                        },
                        element:{
                            label: '省',
                            type: 'select',
                            select: {
                                url: this.$baseURL.base + '/base/area/list?parentCode=country_zhongguo&typeDictCode=province'
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'cityAreaId'
                        },
                        element:{
                            label: '城市',
                            disabled: (form)=>{
                                return !form.provinceAreaId
                            },
                            type: 'select',
                            select: {
                                url: (form)=>{
                                    if (!form.provinceAreaId) {
                                        return null
                                    }
                                    return this.$baseURL.base + '/base/area/list?parentId=' + form.provinceAreaId
                                }
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'districtAreaId'
                        },
                        element:{
                            label: '区',
                            disabled: (form)=>{
                                return !form.cityAreaId
                            },
                            type: 'select',
                            select: {
                                url: (form)=>{
                                    if (!form.cityAreaId) {
                                        return null
                                    }
                                    return this.$baseURL.base + '/base/area/list?parentId=' + form.cityAreaId
                                }
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'businessDistrictId'
                        },
                        element:{
                            label: '商圈',
                            disabled: (form)=>{
                                return !form.districtAreaId
                            },
                            type: 'select',
                            select: {
                                url: (form)=>{
                                    if (!form.districtAreaId) {
                                        return null
                                    }
                                    return this.$baseURL.composite + '/composite/businessdistrict/list?districtAreaId=' + form.districtAreaId
                                }
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'address'
                        },
                        element:{
                            label: '地址全名',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'addressAlias'
                        },
                        element:{
                            label: '地址别名',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'coverImageUrl'
                        },
                        element:{
                            label: '封面图',
                            type: 'upload',
                            upload: {
                                type: 'uploadInput',
                                accept: 'image/*'
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'coverArea'
                        },
                        element:{
                            label: '占地面积(m²)',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'buildingArea'
                        },
                        element:{
                            label: '建筑面积(m²)',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'plotRatio'
                        },
                        element:{
                            label: '容积率',
                            type: 'inputNumber',
                            inputNumber: {
                                precision: 1,
                                step: 0.1
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'greenRatio'
                        },
                        element:{
                            label: '绿化率(%)',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'aboveGroundParkingSpaceNum'
                        },
                        element:{
                            label: '地上车位数',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'belowGroundParkingSpaceNum'
                        },
                        element:{
                            label: '地下车位数',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'parkingRatio'
                        },
                        element:{
                            label: '车位占比',
                            text:{
                                prepend: '1:'
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'areaMin'
                        },
                        element:{
                            label: '面积区间最小值(m²)',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'areaMax'
                        },
                        element:{
                            label: '面积区间最大值(m²)',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'buildAt'
                        },
                        element:{
                            label: '始建于',
                            type: 'date',
                            date:{
                                type: 'date',
                                valueFormat: 'timestamp'
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'builtAt'
                        },
                        element:{
                            label: '建成于',
                            type: 'date',
                            date:{
                                type: 'date',
                                valueFormat: 'timestamp'
                            },
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'developerCompanyId',
                            developerCompanyId__label: ''
                        },
                        element:{
                            type: 'selectRemote',
                            selectRemote:{
                                url: this.$baseURL.crm + '/crm/company/listPage',
                            },
                            label: '开发商公司',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'propertyCompanyId',
                            propertyCompanyId__label: ''
                        },
                        element:{
                            type: 'selectRemote',
                            selectRemote:{
                                url: this.$baseURL.crm + '/crm/company/listPage',
                            },
                            label: '物业公司',
                        }
                    },
                    {
                        field: {
                            name: 'loopLineDictId'
                        },
                        element:{
                            type: 'selectDict',
                            selectDict:{
                                groupCode: 'loop_line',
                            },
                            label: '环线位置',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'version'
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'put',
                                    url: this.$baseURL.house + '/house/estate/' +this.$route.params.id,
                                    label: '保存'
                                },
                                {
                                    action: 'reset',
                                    label: '重置',
                                    type: 'default'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        mounted(){
        },
        methods:{
            longitudeBtnClick () {
                let form =this.$refs.form.getFormData()
                this.$refs.baiduMapLocationDialog.show(form.longitude,form.latitude)

            },
        }
    }
</script>

<style scoped>

</style>